package com.eigaland.change_machine.business.setting

import android.view.View
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.eigaland.change_machine.BR
import com.eigaland.change_machine.R
import com.eigaland.change_machine.adapter.BaseBindAdapter
import com.eigaland.change_machine.business.movielist.MovieListItemVM
import com.eigland.eigaland_lib.base.BaseLazyFragment
import com.google.gson.Gson
import com.orhanobut.logger.Logger
import kotlinx.android.synthetic.main.fragment_setting.*
import kotlinx.android.synthetic.main.fragment_show_list.*

public class SettingFragment :BaseLazyFragment<SettingFragmentVM,com.eigaland.change_machine.databinding.FragmentSettingBinding>(){

    private val settingListAdapter by lazy { BaseBindAdapter<SettingItemVM>(R.layout.item_setting_list, BR.settingItemVM) }


    override fun initVM() {

        vm?.settingList?.observe(this, Observer {data->

            Logger.e("setting data-->" + Gson().toJson(data))

            settingListAdapter?.run {
                this.setNewData(data)
            }
            rv_setting_list.layoutManager = LinearLayoutManager(requireContext())
            rv_setting_list.adapter = settingListAdapter

        })
        vm?.initData()
    }

    override fun setUpViewData(view: View) {
        vm  = SettingFragmentVM()
        binding?.let{
            it.settingVM = vm
            it.lifecycleOwner = this
        }

    }

    override fun setLayoutId() = R.layout.fragment_setting

}